﻿#define DEBUG_UI

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using WPF_DbCenter.SqlServer.DataExchange;



namespace WPF_DbCenter.SqlServer
{
    /// <summary>
    /// Interaction logic for SqlServerIDE.xaml
    /// </summary>
    public partial class SqlServerIDE : Window
    {
        CoreEA.ICoreEAHander core;

        public SqlServerIDE(CoreEA.ICoreEAHander inCore)
        {

            Xceed.Wpf.Controls.Licenser.LicenseKey = Properties.Settings.Default.MyXceedGridLisencer;
            Xceed.Wpf.DataGrid.Licenser.LicenseKey = Properties.Settings.Default.MyXceedGridLisencer;
            this.WindowState = WindowState.Maximized;

            InitializeComponent();
            this.Loaded += new RoutedEventHandler(SqlServerIDE_Loaded);
            core = inCore;
        }

        void SqlServerIDE_Loaded(object sender, RoutedEventArgs e)
        {
#if DEBUG_UI
           
#else 
             LoadDbInfo();
#endif
        }

        /// <summary>
        /// Background thread
        /// </summary>
        private void LoadDbInfo()
        {
            BackgroundWorker bg = new BackgroundWorker();
            this.treeView1.Items.Clear();
            bg.WorkerReportsProgress = true;
            bg.DoWork += delegate(object s1, DoWorkEventArgs se)
            {
                List<string> dbList = core.GetDatabaseList();

                foreach (string item in dbList)
                {
                    CommonMethod.TreeItemArgs args = new WPF_DbCenter.CommonMethod.TreeItemArgs();
                    args.ColumnName = string.Empty;
                    args.IndexName = string.Empty;
                    args.ItemType = CommonMethod.TreeItemType.Database;
                    args.TableName = string.Empty;
                    args.DataBaseName = item;
                    bg.ReportProgress(0, args);
                }

            };

            bg.ProgressChanged += delegate(object s2, ProgressChangedEventArgs args)
            {
                CommonMethod.TreeItemArgs item = args.UserState as CommonMethod.TreeItemArgs;
                if (item != null)
                {
                    TreeViewItem treeItem = new TreeViewItem();
                    treeItem.Header = item.DataBaseName;
                    treeItem.Tag = item;
                    
                }
            };

            bg.RunWorkerAsync();
        }

        private void syncInSqlServer_Click(object sender, RoutedEventArgs e)
        {
            SyncDataInSqlServer sds = new SyncDataInSqlServer();
            
        }

    }
}
